package body_store

import (
	"fmt"
	"go_skill_point/pkg/apiserver/response"
	"go_skill_point/pkg/metrics"
	"math/rand"
	_ "net/http/pprof"
	"time"

	"github.com/gin-gonic/gin"
)

type BodyStoreController struct {
}

type Student struct {
	Name  string `json:"name"`
	Age   int    `json:"age"`
	Socre int    `json:"score"`
}

func NewBodyStoreController() *BodyStoreController {
	return &BodyStoreController{}
}

func (b *BodyStoreController) Test1(ctx *gin.Context) {
	metrics.FlowBodyStoreInputCount.Inc(1)
	response.Response(ctx, 200, "请求成功", "返回的内容")
}

func (b *BodyStoreController) Test2(ctx *gin.Context) {
	metrics.FlowBodyStoreCompleteCount.Inc(2)
	response.Response(ctx, 200, "请求成功", Student{
		Name:  "张三",
		Age:   30,
		Socre: 100,
	})
}

func (b *BodyStoreController) Test3(ctx *gin.Context) {
	// 开启pprof监测
	// go func() {
	// 	fmt.Println(http.ListenAndServe("0.0.0.0:8005", nil))
	// }()

	for i := 0; i < 100000000; i++ {
		fmt.Sprintf("zhangsan_%v", rand.Intn(100000))
		// fmt.Println(Name)
	}

	// ConsumeTime1()

	response.Response(ctx, 200, "请求成功", "Test3返回的内容")
}

func ConsumeTime1() {
	time.Sleep(time.Second * 5)
	ConsumeTime2()
}

func ConsumeTime2() {
	time.Sleep(time.Second * 4)
}
